package com.ztftrue.ble;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by ztftrue on 2017/6/15
 */

public class ListAda extends BaseAdapter {

    private List<BleClass> data;
    private LayoutInflater layoutInflater;
    private Context context;

    public ListAda(Context context, List<BleClass> data) {
        this.context = context;
        this.data = data;
        this.layoutInflater = LayoutInflater.from(context);
    }

    /**
     * 组件集合，对应list.xml中的控件
     *
     * @author Administrator
     */
    public final class Zujian {
        public TextView uuidT;
        public TextView minorT;
        public TextView majorT;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    /**
     * 获得某一位置的数据
     */
    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    /**
     * 获得唯一标识
     */
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Zujian zujian = null;
        if (convertView == null) {
            zujian = new Zujian();
            //获得组件，实例化组件
            convertView = layoutInflater.inflate(R.layout.list, null);
            zujian.majorT = (TextView) convertView.findViewById(R.id.majorT);
            zujian.minorT = (TextView) convertView.findViewById(R.id.minorT);
            zujian.uuidT = (TextView) convertView.findViewById(R.id.uuidT);
            convertView.setTag(zujian);
        } else {
            zujian = (Zujian) convertView.getTag();
        }
        //绑定数据

        zujian.majorT.setText(String.valueOf(data.get(position).getMajor()));
        zujian.minorT.setText(String.valueOf(data.get(position).getMinor()));
        if (data.get(position).getUuid() != null) {
            zujian.uuidT.setText(data.get(position).getUuid());
        }
        return convertView;
    }

}